package com.carlyang.jspservlet.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PrintWriter out = null;
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		response.setCharacterEncoding("gbk");//gbk必须小写才能显示中文，大写GBK请求时会报错
		out = response.getWriter();
		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<head><title>HelloWorld Servlet</title></head>");
		out.println("<body>");
		out.println("<h1>Hello Servlet 你好，Servlet！</h1>");
		out.println("get请求跳转post<br>");
		this.doPost(request, response);//get请求交给Post处理
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		out.println("doPost处理<br>");
		out.println("</body>");
		out.println("</html>");
		out.close();
	}
	
}
